<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\Users;
class Product extends Model
{
    use HasFactory;

    public function search($data)
    {
		$page_size = isset($data['page_size'])?$data['page_size']:10;
		if(isset($data['keyword'])){
			$keyword = $data['keyword'];
			$where['p.title|c.title'] = ['LIKE',"%$keyword%"];
		}else{
			$where = [];
		}

        // return $where;
        // ->LEFTJOIN('categories as c','c.id = p.category_id')
        $list = $this->from('products as p')->paginate($page_size);
        return $list;

		$count = $this->from('products as p')->where(['p.id'=>131])->count();

		return ['list'=>$list,'count'=>$count];
    }

    public function Category()
    {
    	return $this->hasone(Category::class);
    }

    public function Sku()
    {
        return $this->hasmany(ProductSku::class);
    }

    public function Description()
    {
    	return $this->hasone(ProductDescription::class);
    }

    public function Image()
    {
    	return $this->hasMany(Image::class);
    }


}
